package thread.state.intercept;

public class ThreadInterceptTest {
    public static void main(String[] args) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();

                long startTime = System.currentTimeMillis();
                long curTime = startTime;
                while (!isInterrupted()) {
                    long tmpCurTime = System.currentTimeMillis();
                    if ((tmpCurTime - curTime) > 1000) {
                        curTime = tmpCurTime;
                        System.out.println("currentTome = " + curTime);
                    }
                }

                System.out.println("Thread " + Thread.currentThread().getName() + " has interrupted!");
            }
        };

        thread.start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        thread.interrupt();
    }
}
